//
//  KLChangePayPwdViewController.m
//  KISSLOCK
//
//  Created by 陈宾鹏 on 16/8/11.
//  Copyright © 2016年 陈宾鹏. All rights reserved.
//

#import "KLChangePayPwdViewController.h"
#import "KLHelp.h"
#import "KLHttpAPI.h"
#import "FMDBTool.h"
#import "Masonry.h"
#import "HemaConst.h"
#import "JRToast.h"
#import "KLSetPayPasswordViewController.h"

@interface KLChangePayPwdViewController ()
@property (weak, nonatomic) IBOutlet UIView *superView;
@property (weak, nonatomic) IBOutlet UITextField *oldPwdTf;
@property (weak, nonatomic) IBOutlet UIButton *btnSure;

@end

@implementation KLChangePayPwdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self naveSet];
    self.superView.backgroundColor = [UIColor whiteColor];
    self.superView.layer.masksToBounds = YES;
    self.superView.layer.cornerRadius = 6;
    self.superView.layer.borderWidth = 0.8f;
    self.superView.layer.borderColor = RGB_UI_COLOR(204, 204, 204).CGColor;
    
    self.btnSure.layer.masksToBounds = YES;
    self.btnSure.layer.cornerRadius = 5;
    self.btnSure.layer.borderWidth = 1.0f;
    self.btnSure.layer.borderColor = RGB_UI_COLOR(51, 153, 255).CGColor;
    
    [self.oldPwdTf becomeFirstResponder];
}

- (IBAction)complete:(UIButton *)sender {
    if(self.oldPwdTf.text.length == 0){
        [JRToast showWithText:@"请输入旧密码"];
        return ;
    }
    
    [KLHttpAPI requestChangePasswordToken:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] keytype:@"2" oldPassword:self.oldPwdTf.text newPassword:self.oldPwdTf.text completionHandler:^(NSString *responseString) {
        NSLog(@"%@",responseString);
        NSDictionary *dic = [KLHelp dictionaryWithJsonString:responseString];
        NSString *isSuccess = [dic objectForKey:@"success"];
        if(isSuccess.integerValue == 1){
            KLSetPayPasswordViewController *setPayPwdVC = [[KLSetPayPasswordViewController alloc]init];
            [self.navigationController presentViewController:setPayPwdVC animated:YES completion:nil];
        }else{
            [JRToast showWithText:@"旧密码输入错误"];
        }
    } errorHandler:^(NSString *error) {
    }];
}

#pragma mark - 界面设置
//初始化导航栏
-(void)naveSet{
    self.view.backgroundColor = RGB_UI_COLOR(242, 242, 242);
    self.navigationController.navigationBarHidden = NO;
    self.title = @"修改支付密码";
    
    [KLHelp navSet:self doBackHandeler:^(UIButton *backButton) {
        [backButton addTarget:self action:@selector(doBack:) forControlEvents:UIControlEventTouchUpInside];
    }];
}-(void)doBack:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
@end
